using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using MyMvcApp.Models;

namespace MyMvcApp.Controllers;

public class TestController : Controller
{
    // 生成一个随机整数，范围[0,100]，注意是否包含
    public IActionResult GetRandom1()
    {
        Random random = new Random();
        return Content(random.Next(0, 101).ToString());
    }

    // 生成一个随机整数，范围(0,100]，注意是否包含
    public IActionResult GetRandom2()
    {
        Random random = new Random();
        return Content(random.Next(1, 101).ToString());
    }

    // 生成10个随机整数，范围[5, 80],注意是否包含
    public IActionResult GetRandom3()
    {
        Random random = new Random();
        string text = "";

        for (int i = 0; i < 10; i++)
        {
            text = text + random.Next(5, 81);
            if (i < 9)
            {
                text += " ";
            }
        }
        return Content(text);
    }

    // 定义一个字符串，字符串中有100个中文字符，需要从中随机取1个字符串
    public IActionResult GetRandom4()
    {
        string ChineseString = "春风拂面绿意盎然大地回春万物复苏每片叶子都在欢唱每一朵花儿都在绽放走在这片生机勃勃的土地上感受到大自然的美好与宁静生活如同四季交替有时波澜壮阔有时安静但无论怎样始终充满希望带来新的希望大地回春万物复苏";
        Random random = new Random();
        int index = random.Next(ChineseString.Length);
        return Content(ChineseString[index].ToString());
    }

    // 定义一个字符串，字符串中有100个中文字符，需要从中随机取5-50个字符，组成新的字符
    public IActionResult GetRandom5()
    {
        string ChineseString = "春风拂面绿意盎然大地回春万物复苏每片叶子都在欢唱每一朵花儿都在绽放走在这片生机勃勃的土地上感受到大自然的美好与宁静生活如同四季交替有时波澜壮阔有时安静但无论怎样始终充满希望带来新的希望大地回春万物复苏";

        Random random = new Random();

        int RandomNumber = random.Next(5, 51);
        string text = "";
        for (int i = 0; i < RandomNumber; i++)
        {
            int index = random.Next(ChineseString.Length);
            text += ChineseString[index].ToString();
            if (i < RandomNumber - 1)
            {
                text += " ";
            }
        }
        return Content(text);
    }

    // 定义2个字符串，第一个字符串中放百家姓，第二个字符串中放中文字符，要求从第一个字符串随机取得一个姓，再从第二个字符串中随机获得1到2个字符组成新字符串，和第一个字符串取得的姓组成一个姓名
    public IActionResult GetRandom6()
    {
        string baijiaxing = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹孟高林何马陶冯程严唐";
        string chineseChars = "春风拂面绿意盎然大地回春万物复苏每片叶子都在欢唱每一朵花儿都在绽放走在这片生机勃勃的土地上感受到大自然的美好与宁静生活如同四季交替有时波澜壮阔有时安静但无论怎样始终充满希望带来新的希望大地回春万物复苏";

        Random random = new Random();

        int LastNameRandom = random.Next(baijiaxing.Length);
        string LastNameText = baijiaxing[LastNameRandom].ToString();

        string FirstNameText = "";

        // 1-2
        int FirstNameRandomNumber = random.Next(1, 3);
        for (int i = 0; i < FirstNameRandomNumber; i++)
        {
            int FirstNameRandom2 = random.Next(chineseChars.Length);
            string FirstNameChar = chineseChars[FirstNameRandom2].ToString();

            FirstNameText += FirstNameChar;
        }
        return Content(LastNameText + FirstNameText);
    }

    public IActionResult GetRandom7()
    {
        string baijiaxing = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹孟高林何马陶冯程严唐";
        string chineseChars = "伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博诚先敬震振壮会思群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾楠榕风航弘";

        Random random = new Random();

        // 定义一个列表用于存储100个随机生成的 BlogCreateDto
        var blogList = new List<BlogCreateDto>();

        // 生成100个 BlogCreateDto 对象
        for (int i = 0; i < 100; i++)
        {
            // 随机生成标题 Title
            int titleLength = random.Next(5, 11);
            string title = "";

            for (int t = 0; t < titleLength; t++)
            {
                int index = random.Next(chineseChars.Length);
                title += chineseChars[index];
            }

            // 随机生成作者 Author

            int LastNameRandom = random.Next(baijiaxing.Length);
            string LastNameText = baijiaxing[LastNameRandom].ToString();

            string FirstNameText = "";
            int FirstNameRandomNumber = random.Next(1, 3);
            for (int j = 0; j < FirstNameRandomNumber; j++)
            {
                int FirstNameRandom2 = random.Next(chineseChars.Length);
                string FirstNameChar = chineseChars[FirstNameRandom2].ToString();

                FirstNameText += FirstNameChar;
            }
            string author = LastNameText + FirstNameText;

            // 随机生成内容 Content
            int randomContentLength = random.Next(20, 50);
            string content = "";
            for (int k = 0; k < randomContentLength; k++)
            {
                int contentIndex = random.Next(chineseChars.Length);
                content += chineseChars[contentIndex].ToString();
            }

            BlogCreateDto blog = new BlogCreateDto
            {
                Title = title,
                Author = author,
                Content = content
            };

            blogList.Add(blog);
        }

        return View(blogList);
    }
}